//
//  GWMyTabBar.m
//  新浪微博
//
//  Created by qianfeng on 16/1/11.
//  Copyright (c) 2016年 高炜. All rights reserved.
//

#import "GWMyTabBar.h"
@interface GWMyTabBar()
@property (nonatomic,weak)UIButton *plusBtn;
@end
@implementation GWMyTabBar
-(instancetype)init
{
    if (self =[super init]) {
        [self createPlusBtn];
        
    }
    return self;
}
-(void)createPlusBtn
{
    UIButton *btn =[[UIButton alloc]init];
    [btn setImage:[UIImage imageWithName:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageWithName:@"tabbar_compose_button"] forState:UIControlStateNormal];
    
    [btn setImage:[UIImage imageWithName:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
    [btn setBackgroundImage:[UIImage imageWithName:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
    [btn addTarget:self action:@selector(plusBtnOnClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
    self.plusBtn =btn;
}
-(void)plusBtnOnClick
{
    
    if ([self.delegate respondsToSelector:@selector(myTabBarDidPuls:)]) {
        [self.delegate myTabBarDidPuls:self];
    }
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    int index =0;
    CGFloat btnW =self.width/(self.items.count+1);
    CGFloat btnH =self.height;
    for (UIView *tabBarBtn in self.subviews) {
        if (![tabBarBtn isKindOfClass:NSClassFromString(@"UITabBarButton")])continue;
        tabBarBtn.width =btnW;
        tabBarBtn.height =btnH;
        if (index>=2) {
            tabBarBtn.x =btnW*(index+1);
        }
        else
        {
            tabBarBtn.x =btnW*index;
        }
        tabBarBtn.y=0;
        
        index++;
    }
    self.plusBtn.size =self.plusBtn.currentBackgroundImage.size;
    self.plusBtn.center =CGPointMake(self.width*0.5, self.height*0.5);
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
